package com.itbour.service.yjx.trade.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.common.util.StringUtils;
import com.itbour.dao.yjx.trade.YjxSearchTagDao;
import com.itbour.dto.yjx.trade.YjxSearchTagDto;
import com.itbour.service.yjx.trade.YjxSearchTagService;

public class YjxSearchTagServiceImpl implements YjxSearchTagService {

	
	private YjxSearchTagDao yjxSearchTagDao;
	
	public YjxSearchTagDao getYjxSearchTagDao() {
		return yjxSearchTagDao;
	}

	public void setYjxSearchTagDao(YjxSearchTagDao yjxSearchTagDao) {
		this.yjxSearchTagDao = yjxSearchTagDao;
	}

	@Override
	public Page pageTagInfoPg(Map<String, Object> param, Integer pageNo,
			Integer pageSize) {
		Page result = null;
		
		// 实际起始位置
		int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
		int totalSize = yjxSearchTagDao.yjxSearchTagCnt(param);
		
		while(totalSize >0 && totalSize <= skipResults){
			skipResults= skipResults - pageSize;
			pageNo = pageNo -1;
		}
		
		// 分页检索
		param.put("pageSize", pageSize);
		param.put("skipResults", skipResults);
		List<YjxSearchTagDto> data = yjxSearchTagDao.yjxSearchTag(param);

		result = new JspPage(skipResults, totalSize, pageSize, data);
		return result;
	}

	@Override
	public void updSearch(Map<String, Object> param) {
		yjxSearchTagDao.updateYjxSearchTagById(param);

	}

	@Override
	public void delSearch(String ids) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("ids", StringUtils.listToString2(StringUtils.stringToList2(ids)));
		yjxSearchTagDao.deleteYjxSearchTagLogic(param);

	}

	@Override
	public void addSearch(YjxSearchTagDto searchTag) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("name", searchTag.getName());
		param.put("type", searchTag.getType());
		param.put("create_time", searchTag.getCreate_time());
		param.put("update_by", searchTag.getUpdate_by());
		yjxSearchTagDao.insertYjxSearchTag(param);

	}

	@Override
	public List<YjxSearchTagDto> selectSearchInfo(Map<String, Object> param) {
		return yjxSearchTagDao.selectYjxSearchTag(param);
	}

}
